﻿using CodeMinder.Output.MotionChart.Entities;
using NUnit.Framework;
using Rhino.Mocks;

namespace CodeMinder.Output.MotionChart.Tests
{
    [TestFixture]
    public class OptionsTests
    {
        #region Ctor Tests
        [Test]
        public void Ctor_WhenCalling_SettingAllPropertiesToDefaultValue()
        {
            //Act:
            var options = new Options();

            //Assert:
            Assert.AreEqual(500, options.Width);
            Assert.AreEqual(300, options.Height);
            Assert.IsNull(options.State);
            Assert.IsTrue(options.ShowChartButtons);
            Assert.IsTrue(options.ShowHeader);
            Assert.IsTrue(options.ShowSelectListComponent);
            Assert.IsTrue(options.ShowSidePanel);
            Assert.IsTrue(options.ShowXMetricPicker);
            Assert.IsTrue(options.ShowYMetricPicker);
            Assert.IsTrue(options.ShowXScalePicker);
            Assert.IsTrue(options.ShowYScalePicker);
            Assert.IsTrue(options.ShowAdvancedPanel);
        }
        #endregion

        #region ToScript Tests
        [Test]
        public void ToScript_WithDefaultValues_ReturnsTheDefaultScript()
        {
            //Arrange:
            const string expected =
@"var options = {};
";
            var options = new Options();

            //Act:
            var actual = options.ToScript();

            //Assert:
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void ToScript_WithNonDefaultValues_ReturnsTheCorrectScriptAccordingToProperties()
        {
            //Arrange:
            const string expected =
@"var options = {{}};
options['width'] = 800;
options['height'] = 400;
options['state'] = {0};
options['showChartButtons'] = false;
options['showHeader'] = false;
options['showSelectListComponent'] = false;
options['showSidePanel'] = false;
options['showXMetricPicker'] = false;
options['showYMetricPicker'] = false;
options['showXScalePicker'] = false;
options['showYScalePicker'] = false;
options['showAdvancedPanel'] = false;
";
            const string stateString = "blabla";

            var stubState = MockRepository.GenerateStub<State>();
            stubState.Stub(x => x.ToScript()).Return(stateString);

            var options = new Options
                              {
                                  Height = 400,
                                  Width = 800,
                                  State = stubState,
                                  ShowChartButtons = false,
                                  ShowHeader = false,
                                  ShowSelectListComponent = false,
                                  ShowSidePanel = false,
                                  ShowXMetricPicker = false,
                                  ShowYMetricPicker = false,
                                  ShowXScalePicker = false,
                                  ShowYScalePicker = false,
                                  ShowAdvancedPanel = false,
                              };
            //Act:
            var actual = options.ToScript();

            //Assert:
            Assert.AreEqual(string.Format(expected, stateString), actual);
        }
        #endregion
    }
}